package io.github.topcatv.mall.common.ao;

import io.github.topcatv.mall.model.sys.entity.User;
import lombok.Data;
import org.springframework.cglib.beans.BeanCopier;

import java.io.Serializable;
import java.util.List;

/**
 * @author liuyi
 */
@Data
public class UserAo implements Serializable {
    private static final BeanCopier USER_COPIER = BeanCopier.create(User.class, UserAo.class, false);
    private static final BeanCopier ENTITY_COPIER = BeanCopier.create(UserAo.class, User.class, false);
    private Integer id;
    private String username;
    private String mobile;
    private String avatar;
    private String originPwd;
    private String pwd;
    private Boolean locked;
    private Boolean credentialsExpired;
    private List<MenuAo> menus;
    private List<PermissionAo> permissions;
    private List<RoleAo> roles;

    public UserAo() {
    }

    public UserAo(User user) {
        USER_COPIER.copy(user, this, null);
    }

    public User toEntity() {
        User user = new User();
        ENTITY_COPIER.copy(this, user, null);
        return user;
    }
}
